<?php

$aOurWork = get_post_meta($post->ID, $post->post_type, true);
$aOurWork = isset($aOurWork['ourwork']) ? $aOurWork['ourwork'] : array();

qva_ourwork($aOurWork);

function qva_ourwork($data)
{
	$instance = wp_parse_args($data, array('link'=>'#', 'image_id'=>''));

	?>
	<div class="postbox">
		<div class="handlediv" title="Click to toggle">
            <br>
        </div>
        <h3 class="hndle">
            <span>Our Work</span>
        </h3>
        <div class="inside">
        	<div class="bt-reset">
	        	<div class="container-12-fluid">
					<div class="container-12-row">
						<div class="large-12">
							<div class="body">

								<div class="form-group">
			                        <label class="form-label">Link to our work</label>
			                        <div class="controls">
			                            <input type="text" value="<?php echo stripslashes($instance['link']); ?>" name="ourwork[link]" class="form-control">
			                        </div>
			                    </div>

			                    <div class="form-group gallery-wrapper">
			                    	<label class="form-label">Upload Images</label>
			                    	<div class="controls wrap-upload">
			                    		<input type="text" class="box-image-id" name="ourwork[image_id]" value="<?php echo isset($instance['image_id']) ? $instance['image_id'] : $instance['image_id']; ?>">
			                    		<input type="button" class="blue-btn btn btn-info upload-image multiple_upload" value="Upload">
			                    	</div>
			                    	<ul class="lux-gallery">
			                    		<?php 
			                    			if ( isset($instance['image_id']) && !empty($instance['image_id']) )  : 
			                    				$parse = explode(",", $instance['image_id']);
			                    				foreach ($parse as $id)
			                    				{
			                    					?>
			                    					<li class="attachment img-item width-300" data-id="<?php echo $id; ?>">
			                    						<?php echo wp_get_attachment_image($id, 'thumbnail'); ?>
														<a class="md-remove" href="#">
															<i class="fa fa-times"></i>
														</a>
													</li>
			                    					<?php 
			                    				}
			                    			endif;
			                    		?>
			                    	</ul>
			                    </div>

							</div>
						</div>
					</div>
				</div>
			</div>
        </div>
	</div>
	<?php 
}

